# Example file showing a basic pygame "game loop"
from collections.abc import Callable, Iterable, Mapping
from typing import Any
import pygame
import threading


class DisplayThread(threading.Thread):
    
    def __init__(self, group: None = None, target: Callable[..., object] | None = None, name: str | None = None, args: Iterable[Any] = ..., kwargs: Mapping[str, Any] | None = None, *, daemon: bool | None = None) -> None:
        super().__init__(group, target, name, args, kwargs, daemon=daemon)
        self.__quit = False
    
    def run(self):
        self.__show_window()
        
    @property
    def bg(self):
        return self.__bg;
    @bg.setter
    def bg(self, value):
        self.__bg = value;
        
    def __show_window(self):
        pygame.init()
        a = pygame.display.get_desktop_sizes()
        screen = pygame.display.set_mode((a[0][0]/2, a[0][1]/2))
        clock = pygame.time.Clock()
        while not self.__quit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.__quit = True
            screen.fill("white")
            if self.__bg:
                screen.blit(self.__bg, self.__bg.get_rect())
            pygame.display.flip()
            clock.tick(60)
        pygame.quit()

thread = DisplayThread()

def show():
    thread.start()

def quit():
    thread.__quit = True

    
def set_bg(img_url):
    thread.bg = pygame.image.load(img_url)